const Router = require('koa-router');
const router = new Router();
const dormitoryController = require('../controllers/dormitory.controller');
const authMiddleware = require('../middlewares/auth.middleware');

// 宿舍相关API路由

// 获取所有宿舍列表
router.get('/', authMiddleware.authenticateToken, dormitoryController.getAllDormitories);

// 获取单个宿舍信息
router.get('/:id', authMiddleware.authenticateToken, dormitoryController.getDormitoryById);

// 创建新宿舍
router.post('/', authMiddleware.authenticateToken, authMiddleware.authorize(['admin']), dormitoryController.createDormitory);

// 更新宿舍信息
router.put('/:id', authMiddleware.authenticateToken, authMiddleware.authorize(['admin']), dormitoryController.updateDormitory);

// 删除宿舍
router.delete('/:id', authMiddleware.authenticateToken, authMiddleware.authorize(['admin']), dormitoryController.deleteDormitory);

// 分页获取宿舍列表
router.get('/paginated/list', authMiddleware.authenticateToken, dormitoryController.getDormitoriesPaginated);

// 根据楼栋获取宿舍列表
router.get('/by-building/:building', authMiddleware.authenticateToken, dormitoryController.getDormitoriesByBuilding);

// 获取宿舍的学生列表
router.get('/:id/students', authMiddleware.authenticateToken, dormitoryController.getDormitoryStudents);

// 获取空宿舍列表
router.get('/status/empty', authMiddleware.authenticateToken, dormitoryController.getEmptyDormitories);

module.exports = router;